import java.util.Arrays;
import java.util.Scanner;

public class FindString {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        in.nextLine();
        if (m < 1 || m > n) {
            System.out.println("m is out of range");
            return;
        }
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = in.nextLine();

        }

//        for (int i = 0; i < n - 1; i++)
//            for (int j = 0; j < n - i - 1; j++)
//                if (s[j].compareTo(s[j + 1]) < 0) {
//                    String tmp = s[j];
//                    s[j] = s[j + 1];
//                    s[j + 1] = tmp;
//                }
//        System.out.println(s[m]);
        Arrays.sort(s);
        System.out.println(s[s.length - m]);
    }

}
